package Server.ServerCore.Service.Logic;

import Server.ExtComponents.BaseConfig.MServerConfig;
import Server.ExtComponents.utilsKit.PriorityThreadFactory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

public class ThreadPoolManager {

    private static ExecutorService _aiScheduledThreadPool ;//AI
    private static ExecutorService _BattleScheduledThreadPool ;//battle


    private ThreadPoolManager(){
        _aiScheduledThreadPool=new ScheduledThreadPoolExecutor(MServerConfig.AIThreadNums, new PriorityThreadFactory("AIThread", Thread.NORM_PRIORITY));
        _BattleScheduledThreadPool=new ScheduledThreadPoolExecutor(MServerConfig.BattleThreadNums,new PriorityThreadFactory("BattleThread", Thread.NORM_PRIORITY));

    }


    /**
     * AI 执行线程
     * @param AiRunnable runnableTask
     */
    public void ExecutorAI(Runnable AiRunnable){
        _aiScheduledThreadPool.execute(AiRunnable);
    }

    /**
     * Battle 执行线程
     * @param BattleRunnable
     */
    public void ExecutorBattle(Runnable BattleRunnable){
        _BattleScheduledThreadPool.execute(BattleRunnable);
    }


    public static ThreadPoolManager getThreadManager(){
        return SingletonHolder._instance;
    }


    private static class SingletonHolder{
        protected static final ThreadPoolManager _instance = new ThreadPoolManager();
    }

}
